﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NBearLite;

namespace KMFrame.Core
{
    public class BaseLogic : DebugLogic
    {
        private Database _NBLData = null;

        /// <summary>
        /// 数据库访问
        /// </summary>
        protected Database NBLData { get { return _NBLData; } }

        protected void InitData(string DataStr)
        {
            _NBLData = new Database(DataStr);
        }

        /// <summary>
        /// 获取总记录条数
        /// </summary>
        /// <param name="column">主键</param>
        /// <returns></returns>
        protected int GetTotalRecord(IQueryTable table, QueryColumn column, WhereClip where)
        {
            SelectSqlSection sql = NBLData.Select(table, column.Count());
            object obj = sql.Where(where).ToScalar();
            if (obj != null)
                return Convert.ToInt32(obj);
            else
                return 0;
        }
    }

    public class ConditionCollection
    {
        public SelectSqlSection Select { get; set; }
        public ExpressionClip[] SelectColumns { get; set; }
        public WhereClip Where { get; set; }
    }
}
